package main

import (
	"gitee.com/scottq/go-framework/examples_stc"
	v1config "gitee.com/scottq/go-framework/src/v1/config"
	"log"
	"time"
)

func main() {
	c := v1config.DBConfig{
		DbHost:     "127.0.0.1",
		DbPort:     "3306",
		DbName:     "db_test",
		DbUser:     "root",
		DbPassword: "root",

		MaxLifetime:  30 * int(time.Minute),
		MaxIdleTime:  30 * int(time.Minute),
		MaxOpenConns: 256,
		MaxIdleConns: 80,
		MaxConcatLen: "18446744073709551615",
	}
	log.Printf("config: %+v", c)
	op, err := examples_stc.NewOpMysql(c)
	if err != nil {
		log.Fatalf("new op mysql err:%s", err)
		return
	}

	list, total, err := op.Query()
	if err != nil {
		log.Fatalf("query err:%s", err)
		return
	}
	log.Printf("list: %v", list)
	log.Printf("total: %d", total)


	list, total, err = op.Query()
	if err != nil {
		log.Fatalf("query err:%s", err)
		return
	}
	log.Printf("list: %v", list)
	log.Printf("total: %d", total)

	//
	newOp, err := op.BeginTrans()
	list, total, err = newOp.Query()
	if err != nil {
		log.Fatalf("query err:%s", err)
		return
	}
	defer newOp.RollbackTrans()
	log.Printf("list: %v", list)
	log.Printf("total: %d", total)

}
